/**
 * Caution: Consider this file when using react-scripts
 * 
 * You may delete this file and its occurrences from the project filesystem if you are using GatsbyJS or NextJS version
 */
import React, { useEffect } from 'react';
import { Switch, Route, Redirect } from 'react-router-dom';
import WithLayout from 'WithLayout';
import { Main as MainLayout, Minimal as MinimalLayout, DocsLayout } from './layouts';

import {
  ThemeCollection as ThemeCollectionView,
  //IndexView,
  Home as HomeView,
  Signin as SigninView,
  VerifyPhone as VerifyPhoneView,
  CommunityCategory as CommunityCategoryView,
  Community as CommunityView,
  Artists as ArtistsView,
  Artist as ArtistView,
  Podcasts as PodcastsView,
  Podcast as PodcastView,
  CreateBlog as CreateBlogView,
  Shop as ShopView,
  FAQ as FAQView,
  Publication as PublicationView,
  PublicationDetail as PublicationDetailView,
  Members as MembersView,
  ContactPage as ContactPageView,
  MobileApp as MobileAppView,
  HelpCenter as HelpCenterView,
  HelpCenterArticle as HelpCenterArticleView,
  ContactPageSidebarMap as ContactPageSidebarMapView,
  ContactPageCover as ContactPageCoverView,
  PasswordResetCover as PasswordResetCoverView,
  PasswordResetSimple as PasswordResetSimpleView,
  SignupCover as SignupCoverView,
  Signup as SignupView,
  NumberVerification as NumberVerificationView,
  Account as AccountView,
  Voting as VotingView,
  VotingAll as VotingAllView,
  VotingDetail as VotingDetailView,
  Documentation as DocumentationView,
  NotFound as NotFoundView,
  NotFoundCover as NotFoundCoverView,
  BlogDetail as BlogDetailView,
  Subscription as SubscriptionView,
  Discover as DiscoverView,
  DiscoverDetail as DiscoverDetailView,
  DiscoverAll as DiscoverAllView,
  LiveFeed as LiveFeedView,
  Plays as PlaysView,
  MyProfile as MyProfileView,
  ArtistProfile as ArtistProfileView,
  Follow as FollowView,
  EditPlaylist as EditPlaylistView
} from './views';
import { messageService } from 'utils/messageService';
import { useHistory } from 'react-router-dom/cjs/react-router-dom.min';

const Routes = () => {

  const history = useHistory();

  useEffect(() => {
    messageService.getMessage().subscribe(message => {
      if (message.text == 'SignIn') {
        history.replace('/signin');
      }
    });
  }, [])

  return (
    <Switch>
      <Route
        exact
        path="/"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={HomeView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/themes"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={ThemeCollectionView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/signin/:type/:id"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={SigninView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/signin/:type"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={SigninView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/signin"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={SigninView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/verify-phone"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={VerifyPhoneView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/community"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={CommunityCategoryView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/community/create"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={CreateBlogView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/community/post/:id"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={BlogDetailView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/community/:id"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={CommunityView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/artists"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={ArtistsView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/artist/:id"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={ArtistView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/podcasts"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={PodcastsView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/podcast/:id"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={PodcastView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/shop"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={ShopView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/discover"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={DiscoverView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/discover/all"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={DiscoverAllView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/discover/:id"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={DiscoverDetailView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/live-feed"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={LiveFeedView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/plays/:id"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={PlaysView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/members"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={MembersView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/faq"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={FAQView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/publication"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={PublicationView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/publication/:id"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={PublicationDetailView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/contact-page"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={ContactPageView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/mobile-app"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={MobileAppView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/help-center"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={HelpCenterView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/help-center-article"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={HelpCenterArticleView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/contact-sidebar-map"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={ContactPageSidebarMapView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/contact-page-cover"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={ContactPageCoverView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/number_verification"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={NumberVerificationView}
            layout={MinimalLayout}
          />
        )}
      />
      <Route
        exact
        path="/password-reset-cover"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={PasswordResetCoverView}
            layout={MinimalLayout}
          />
        )}
      />
      <Route
        exact
        path="/password-reset-simple"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={PasswordResetSimpleView}
            layout={MinimalLayout}
          />
        )}
      />
      <Route
        exact
        path="/signup"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={SignupView}
            layout={MinimalLayout}
          />
        )}
      />
      <Route
        exact
        path="/subscription"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={SubscriptionView}
            layout={MinimalLayout}
          />
        )}
      />
      <Route
        exact
        path="/signup-cover"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={SignupCoverView}
            layout={MinimalLayout}
          />
        )}
      />
      <Route
        exact
        path="/account"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={AccountView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/account/edit_playlist"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={EditPlaylistView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/account/my_profile"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={MyProfileView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/account/artist_profile"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={ArtistProfileView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/account/follow"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={FollowView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/voting"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={VotingView}
            layout={MainLayout}
          />
        )}
      />
      
      <Route
        exact
        path="/voting/all"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={VotingAllView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/voting/:id"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={VotingDetailView}
            layout={MainLayout}
          />
        )}
      />
      <Route
        exact
        path="/documentation"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={DocumentationView}
            layout={DocsLayout}
          />
        )}
      />
      <Route
        exact
        path="/not-found"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={NotFoundView}
            layout={MinimalLayout}
          />
        )}
      />
      <Route
        exact
        path="/not-found-cover"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={NotFoundCoverView}
            layout={MinimalLayout}
          />
        )}
      />
      <Redirect to="/not-found-cover" />
    </Switch>
  );
};

export default Routes;
